package com.darren.befriend.fragments;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;

import com.darren.befriend.BaseActivity;
import com.darren.befriend.HomeActivity;
import com.darren.befriend.R;
import com.darren.befriend.constants.Constant;
import com.parse.ParseException;
import com.parse.ParseObject;

public class PersonalityFragment extends HobbyBaseFragment {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		interestTextArr = getResources()
				.getStringArray(R.array.personality_arr);
		mInterestResIds = new int[] { R.drawable.per0, R.drawable.per1,
				R.drawable.per2, R.drawable.per3, R.drawable.per4,
				R.drawable.per5, R.drawable.per6, R.drawable.per7,
				R.drawable.per8, R.drawable.per9, R.drawable.per10,
				R.drawable.per11, R.drawable.per12 };
		if (getArguments() != null) {
			MODE_VALUE = getArguments().getInt(MODE, 0);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {

		mCurrentUser = ((BaseActivity) getActivity()).getCurrentUser();
		if (mCurrentUser != null) {

			ParseObject filter;
			try {

				filter = ((ParseObject) mCurrentUser.get("Filter"))
						.fetchIfNeeded();
				if (filter.containsKey("Personality")) {

					mSelected = (ArrayList<Boolean>) filter.get("Personality");
				}
			} catch (ParseException e) {

			}
		}

		super.onActivityCreated(savedInstanceState);
		if (getActivity() instanceof HomeActivity) {
			mTitle = getString(R.string.friend_personality);
			((HomeActivity) getActivity()).setActivityTitle(mTitle);
			if (MODE_VALUE == SECOND_MODE) {

				((HomeActivity) getActivity())
						.setLeftImage(R.drawable.item_back);
			}
		}
	}

	@Override
	public void onClick(View v) {
		HOBBY_TYPE = Constant.PERSONALITY;
		super.onClick(v);
	}

	public static Fragment create(int mode) {
		PersonalityFragment fragment = new PersonalityFragment();
		Bundle bundle = new Bundle();
		bundle.putInt(MODE, mode);
		fragment.setArguments(bundle);
		return fragment;
	}
}
